<template>
  <a-card :bordered="false">
      <!-- 查询区域 -->
    <div class="table-page-search-wrappe">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="姓名">
              <select-user-by-dep
                  v-model="queryParam.employeeId" :multi="true"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="开始/结束时间">
              <a-range-picker v-model="createTimeRange"
                              format="YYYY-MM-DD"
                              :placeholder="['开始时间', '结束时间']"
                              @change="onCreateTimeChange" />
            </a-form-item>
          </a-col>
          <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="打卡状态">
                <j-dict-select-tag placeholder="请选择打卡状态" v-model="queryParam.status" dictCode="attendance_status"/>
              </a-form-item>
          </a-col> -->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="所属组织">
                <j-select-depart  v-model="queryParam.departId" multi treeOpera/>
              </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset()" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <!-- <a-button @click="handleAdd" type="primary" icon="plus" :disabled="isDisabledAuth('erpEmployeeAttendanceDay:add')">新增</a-button> -->
      <a-button type="primary" icon="download" @click="handleExportXls('员工考勤日报表')" :disabled="isDisabledAuth('erpEmployeeAttendanceDay:export')">导出</a-button>
      <!-- <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import" :disabled="isDisabledAuth('erpEmployeeAttendanceDay:import')">导入</a-button>
      </a-upload> -->
      <!-- 高级查询区域 -->
      <!--<j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>-->
      <!-- <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel" :disabled="isDisabledAuth('erpEmployeeAttendanceDay:delete')"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown> -->
      <a-popover title="自定义列" trigger="click" placement="leftBottom">
        <template slot="content">
          <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
            <a-row>
              <template v-for="(item,index) in defColumns">
                <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                  <a-col :span="12"><a-checkbox :value="item.dataIndex">{{ item.title }}</a-checkbox></a-col>
                </template>
              </template>
            </a-row>
          </a-checkbox-group>
        </template>
        <a style="float: right;"><a-icon type="setting" :style='iconStyle'/></a>
      </a-popover>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">
        <template slot="status" slot-scope="status">
           <a-badge :status="status | statusTypeFilter" :text="status | statusFilter"/>
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <!-- <span slot="action" slot-scope="text, record">
            <a-button
                class="ruleButton"
                :ghost="true"
                type="primary"
                icon="edit"
                @click="handleEdit(record)"
                :disabled="isDisabledAuth('erpEmployeeAttendanceDay:edit')"
        />
        <a-divider type="vertical"/>
        <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
            <a-button
                    class="ruleButton"
                    :ghost="true"
                    type="primary"
                    icon="delete"
                    :disabled="isDisabledAuth('erpEmployeeAttendanceDay:delete')"/>
        </a-popconfirm>
        </span> -->

      </a-table>
    </div>

    <erp-employee-attendance-day-modal ref="modalForm" @ok="modalFormOk"></erp-employee-attendance-day-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import ErpEmployeeAttendanceDayModal from './modules/ErpEmployeeAttendanceDayModal'
  import {DisabledAuthFilterMixin} from '@/mixins/DisabledAuthFilterMixin'
  import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
  import moment from 'moment'

  export default {
    name: 'ErpEmployeeAttendanceDayList',
    mixins:[JeecgListMixin, mixinDevice, DisabledAuthFilterMixin],
    components: {
      ErpEmployeeAttendanceDayModal,
      SelectUserByDep
    },
    data () {
      return {
        createTimeRange:[moment().subtract(1, 'months').startOf('month').format("YYYY-MM-DD"),moment().subtract(1, 'months').endOf('month').format("YYYY-MM-DD")],
        queryParam:{
          dayDate_begin:moment().subtract(1, 'months').startOf('month').format("YYYY-MM-DD"),
          dayDate_end:moment().subtract(1, 'months').endOf('month').format("YYYY-MM-DD")
        },
        description: '员工考勤日报表管理页面',
        //表头
        columns:[],
        //列设置
        settingColumns:[],
        // 列定义
        defColumns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          // {
          //   title:'月表数据',
          //   align:"center",
          //   dataIndex: 'monthId',
          // },
          {
            title:'时间',
            align:"center",
            dataIndex: 'dayDate',
          },
          {
            title:'星期',
            align:"center",
            dataIndex: 'dayOfWeek_dictText',
          },
          {
            title:'姓名',
            align:"center",
            dataIndex: 'employeeId_dictText',
          },
          {
            title:'企业微信账号',
            align:"center",
            dataIndex: 'wxUserId',
          },
          {
            title:'部门',
            align:"center",
            dataIndex: 'departId_dictText',
          },
          {
            title:'职务',
            align:"center",
            dataIndex: 'postId_dictText',
          },
          // {
          //   title:'规则id',
          //   align:"center",
          //   dataIndex: 'groupId',
          // },
          {
            title:'规则名称',
            align:"center",
            dataIndex: 'groupName',
          },
          {
            title:'班次',
            align:"center",
            dataIndex: 'orderOfClasses',
          },
          {
            title:'日报类型',
            align:"center",
            dataIndex: 'dayType_dictText',
          },
          {
            title:'当日打卡次数',
            align:"center",
            dataIndex: 'checkinCount',
          },
          {
            title:'工作时长(小时)',
            align:"center",
            dataIndex: 'regularWorkHour',
          },
          {
            title:'标准工作时长(小时)',
            align:"center",
            dataIndex: 'standardWorkHour',
          },
          {
            title:'最早打卡时间',
            align:"center",
            dataIndex: 'earliestTime',
          },
          {
            title:'最晚打卡时间',
            align:"center",
            dataIndex: 'lastestTime',
          },
          {
            title:'假勤信息',
            align:"center",
            dataIndex: 'spDescription',
          },
          {
            title:'异常信息',
            align:"center",
            dataIndex: 'exceptionDescription',
          },
          {
            title:'迟到次数',
            align:"center",
            dataIndex: 'lateCount',
          },
          {
            title:'迟到时长(分钟)',
            align:"center",
            dataIndex: 'lateDuration',
          },
          {
            title:'早退次数',
            align:"center",
            dataIndex: 'leaveEarlyCount',
          },
          {
            title:'早退时长(分钟)',
            align:"center",
            dataIndex: 'leaveEarlyDuration',
          },
          {
            title:'缺卡次数',
            align:"center",
            dataIndex: 'missingCardCount',
          },
          {
            title:'旷工次数',
            align:"center",
            dataIndex: 'absentWorkCount',
          },
          {
            title:'旷工时长(分钟)',
            align:"center",
            dataIndex: 'absentWorkDuration',
          },
          {
            title:'地点异常次数',
            align:"center",
            dataIndex: 'locationAnomalyCount',
          },
          {
            title:'设备异常次数',
            align:"center",
            dataIndex: 'unitExceptionCount',
          },
          {
            title:'加班状态',
            align:"center",
            dataIndex: 'otStatus_dictText',
          },
          {
            title:'加班时长(分钟)',
            align:"center",
            dataIndex: 'otDuration',
          },
          {
            title:'补卡次数',
            align:"center",
            dataIndex: 'replenishmentCardCount',
          },
          {
            title:'外勤次数',
            align:"center",
            dataIndex: 'fieldWorkCount',
          },
          {
            title:'外出小时',
            align:"center",
            dataIndex: 'outDuration',
          },
          {
            title:'出差天数',
            align:"center",
            dataIndex: 'travelDuration',
          },
          {
            title:'年假天数',
            align:"center",
            dataIndex: 'annualLeaveDuration',
          },
          {
            title:'事假(小时)',
            align:"center",
            dataIndex: 'askLeaveDuration',
          },
          {
            title:'病假(小时)',
            align:"center",
            dataIndex: 'sickLeaveDuration',
          },
          {
            title:'调休假(小时)',
            align:"center",
            dataIndex: 'leaveDuration',
          },
          {
            title:'婚假天数',
            align:"center",
            dataIndex: 'marriageLeaveDuration',
          },
          {
            title:'产假天数',
            align:"center",
            dataIndex: 'maternityLeaveDuration',
          },
          {
            title:'陪产假天数',
            align:"center",
            dataIndex: 'accompanyingLaborDuration',
          },
          {
            title:'哺乳假天数',
            align:"center",
            dataIndex: 'breastfeedingLeaveDuration',
          },
          {
            title:'其他天数',
            align:"center",
            dataIndex: 'otherDuration',
          },
          // {
          //   title:'状态',
          //   align:"center",
          //   dataIndex: 'status',
          // },
          // {
          //   title:'调整状态',
          //   align:"center",
          //   dataIndex: 'adjustStatus',
          // },
          // {
          //   title:'调整时间',
          //   align:"center",
          //   dataIndex: 'adjustTime',
          //   customRender:function (text) {
          //     return !text?"":(text.length>10?text.substr(0,10):text)
          //   }
          // },
          // {
          //   title:'调整人',
          //   align:"center",
          //   dataIndex: 'adjustEmployee',
          // },
          // {
          //   title:'调整说明',
          //   align:"center",
          //   dataIndex: 'adjustRemark',
          // },
          // {
          //   title:'校准状态',
          //   align:"center",
          //   dataIndex: 'standardStatus',
          // },
          // {
          //   title:'是否迟到',
          //   align:"center",
          //   dataIndex: 'isLate_dictText',
          // },
          // {
          //   title:'是否早退',
          //   align:"center",
          //   dataIndex: 'isLeave_dictText',
          // },
          // {
          //   title:'是否旷工',
          //   align:"center",
          //   dataIndex: 'isAbsentWork_dictText',
          // },
          // {
          //   title:'是否缺卡',
          //   align:"center",
          //   dataIndex: 'isMissing_dictText',
          // },
          // {
          //   title:'是否地点异常',
          //   align:"center",
          //   dataIndex: 'isLocationAnomaly_dictText',
          // },
          // {
          //   title:'是否设备异常',
          //   align:"center",
          //   dataIndex: 'isUnitException_dictText',
          // },
          // {
          //   title:'是否工作日加班',
          //   align:"center",
          //   dataIndex: 'isWorkOver_dictText',
          // },
          // {
          //   title:'是否节假日加班',
          //   align:"center",
          //   dataIndex: 'isHolidaysOver_dictText',
          // },
          // {
          //   title:'是否休息日加班',
          //   align:"center",
          //   dataIndex: 'isRestdaysOver_dictText',
          // },
          // {
          //   title:'是否补卡',
          //   align:"center",
          //   dataIndex: 'isReplenishmentCard_dictText',
          // },
          // {
          //   title:'是否外勤打卡',
          //   align:"center",
          //   dataIndex: 'isFieldWork_dictText',
          // },
          // {
          //   title:'是否外出',
          //   align:"center",
          //   dataIndex: 'isOut_dictText',
          // },
          // {
          //   title:'是否出差',
          //   align:"center",
          //   dataIndex: 'isTravel_dictText',
          // },
          // {
          //   title:'是否年假',
          //   align:"center",
          //   dataIndex: 'isAnnualLeave_dictText',
          // },
          // {
          //   title:'是否事假',
          //   align:"center",
          //   dataIndex: 'isAskLeave_dictText',
          // },
          // {
          //   title:'是否病假',
          //   align:"center",
          //   dataIndex: 'isSickLeave_dictText',
          // },
          // {
          //   title:'是否调休',
          //   align:"center",
          //   dataIndex: 'isRestLeave_dictText',
          // },
          // {
          //   title:'是否婚假',
          //   align:"center",
          //   dataIndex: 'isMarriageLeave_dictText',
          // },
          // {
          //   title:'是否产假',
          //   align:"center",
          //   dataIndex: 'isMaternityLeave_dictText',
          // },
          // {
          //   title:'是否陪产假',
          //   align:"center",
          //   dataIndex: 'isAccompanyingLabor_dictText',
          // },
          // {
          //   title:'是否哺乳假',
          //   align:"center",
          //   dataIndex: 'isBreastfeedingLeave_dictText',
          // },
          // {
          //   title:'是否其他假',
          //   align:"center",
          //   dataIndex: 'isOther_dictText',
          // },
          // {
          //   title: '操作',
          //   dataIndex: 'action',
          //   align:"center",
          //   fixed:"right",
          //   width:147,
          //   scopedSlots: {
          //   filterDropdown: 'filterDropdown',
          //   filterIcon: 'filterIcon',
          //   customRender: 'action' }
          // }
        ],
        url: {
          list: "/api/erp/hr/attendance/erpEmployeeAttendanceDay/list",
          delete: "/api/erp/hr/attendance/erpEmployeeAttendanceDay/delete",
          deleteBatch: "/api/erp/hr/attendance/erpEmployeeAttendanceDay/deleteBatch",
          exportXlsUrl: "/api/erp/hr/attendance/erpEmployeeAttendanceDay/exportXls",
          importExcelUrl: "api/erp/hr/attendance/erpEmployeeAttendanceDay/importExcel",
        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      searchReset() {
        this.queryParam = {}
        this.queryParam.dayDate_begin=moment().subtract(1, 'months').startOf('month').format("YYYY-MM-DD")
        this.queryParam.dayDate_end=moment().subtract(1, 'months').endOf('month').format("YYYY-MM-DD")
        this.createTimeRange=[moment().subtract(1, 'months').startOf('month').format("YYYY-MM-DD"),moment().subtract(1, 'months').endOf('month').format("YYYY-MM-DD")]
        this.loadData(1)
      },
      onCreateTimeChange(dateString) {
        this.queryParam.dayDate_begin=moment(dateString[0]).format('YYYY-MM-DD');
        this.queryParam.dayDate_end=moment(dateString[1]).format('YYYY-MM-DD');
      },
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'monthId',text:'月表数据',dictCode:''})
        fieldList.push({type:'string',value:'dayDate',text:'时间',dictCode:''})
        fieldList.push({type:'string',value:'employeeId',text:'姓名',dictCode:''})
        fieldList.push({type:'string',value:'wxUserId',text:'企业微信账号',dictCode:''})
        fieldList.push({type:'string',value:'departId',text:'部门',dictCode:''})
        fieldList.push({type:'string',value:'postId',text:'职务',dictCode:''})
        fieldList.push({type:'string',value:'groupId',text:'规则id',dictCode:''})
        fieldList.push({type:'string',value:'groupName',text:'规则名称',dictCode:''})
        fieldList.push({type:'string',value:'orderOfClasses',text:'班次',dictCode:''})
        fieldList.push({type:'string',value:'dayType',text:'日报类型',dictCode:''})
        fieldList.push({type:'int',value:'checkinCount',text:'当日打卡次数',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'regularWorkHour',text:'工作时长',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'standardWorkHour',text:'标准工作时长',dictCode:''})
        fieldList.push({type:'string',value:'earliestTime',text:'最早打卡时间',dictCode:''})
        fieldList.push({type:'string',value:'lastestTime',text:'最晚打卡时间',dictCode:''})
        fieldList.push({type:'Text',value:'spDescription',text:'假勤信息',dictCode:''})
        fieldList.push({type:'Text',value:'exceptionDescription',text:'异常信息',dictCode:''})
        fieldList.push({type:'int',value:'lateCount',text:'迟到次数',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'lateDuration',text:'迟到时长',dictCode:''})
        fieldList.push({type:'int',value:'leaveEarlyCount',text:'早退次数',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'leaveEarlyDuration',text:'早退时长',dictCode:''})
        fieldList.push({type:'int',value:'missingCardCount',text:'缺卡次数',dictCode:''})
        fieldList.push({type:'int',value:'absentWorkCount',text:'旷工次数',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'absentWorkDuration',text:'旷工时长',dictCode:''})
        fieldList.push({type:'int',value:'locationAnomalyCount',text:'地点异常次数',dictCode:''})
        fieldList.push({type:'int',value:'unitExceptionCount',text:'设备异常次数',dictCode:''})
        fieldList.push({type:'string',value:'otStatus',text:'加班状态',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'otDuration',text:'加班时长',dictCode:''})
        fieldList.push({type:'int',value:'replenishmentCardCount',text:'补卡次数',dictCode:''})
        fieldList.push({type:'int',value:'fieldWorkCount',text:'外勤次数',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'outDuration',text:'外出小时',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'travelDuration',text:'出差天数',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'annualLeaveDuration',text:'年假天数',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'askLeaveDuration',text:'事假(小时)',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'sickLeaveDuration',text:'病假(小时)',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'leaveDuration',text:'调休假(小时)',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'marriageLeaveDuration',text:'婚假天数',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'maternityLeaveDuration',text:'产假天数',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'accompanyingLaborDuration',text:'陪产假天数',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'breastfeedingLeaveDuration',text:'哺乳假天数',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'otherDuration',text:'其他天数',dictCode:''})
        fieldList.push({type:'string',value:'status',text:'状态',dictCode:''})
        fieldList.push({type:'string',value:'adjustStatus',text:'调整状态',dictCode:''})
        fieldList.push({type:'date',value:'adjustTime',text:'调整时间'})
        fieldList.push({type:'string',value:'adjustEmployee',text:'调整人',dictCode:''})
        fieldList.push({type:'Text',value:'adjustRemark',text:'调整说明',dictCode:''})
        fieldList.push({type:'string',value:'standardStatus',text:'校准状态',dictCode:''})
        fieldList.push({type:'string',value:'isLate',text:'是否迟到',dictCode:''})
        fieldList.push({type:'string',value:'isLeave',text:'是否早退',dictCode:''})
        fieldList.push({type:'string',value:'isAbsentWork',text:'是否旷工',dictCode:''})
        fieldList.push({type:'string',value:'isMissing',text:'是否缺卡',dictCode:''})
        fieldList.push({type:'string',value:'isLocationAnomaly',text:'是否地点异常',dictCode:''})
        fieldList.push({type:'string',value:'isUnitException',text:'是否设备异常',dictCode:''})
        fieldList.push({type:'string',value:'isWorkOver',text:'是否工作日加班',dictCode:''})
        fieldList.push({type:'string',value:'isHolidaysOver',text:'是否节假日加班',dictCode:''})
        fieldList.push({type:'string',value:'isRestdaysOver',text:'是否休息日加班',dictCode:''})
        fieldList.push({type:'string',value:'isReplenishmentCard',text:'是否补卡',dictCode:''})
        fieldList.push({type:'string',value:'isFieldWork',text:'是否外勤打卡',dictCode:''})
        fieldList.push({type:'string',value:'isOut',text:'是否外出',dictCode:''})
        fieldList.push({type:'string',value:'isTravel',text:'是否出差',dictCode:''})
        fieldList.push({type:'string',value:'isAnnualLeave',text:'是否年假',dictCode:''})
        fieldList.push({type:'string',value:'isAskLeave',text:'是否事假',dictCode:''})
        fieldList.push({type:'string',value:'isSickLeave',text:'是否病假',dictCode:''})
        fieldList.push({type:'string',value:'isRestLeave',text:'是否调休',dictCode:''})
        fieldList.push({type:'string',value:'isMarriageLeave',text:'是否婚假',dictCode:''})
        fieldList.push({type:'string',value:'isMaternityLeave',text:'是否产假',dictCode:''})
        fieldList.push({type:'string',value:'isAccompanyingLabor',text:'是否陪产假',dictCode:''})
        fieldList.push({type:'string',value:'isBreastfeedingLeave',text:'是否哺乳假',dictCode:''})
        fieldList.push({type:'string',value:'isOther',text:'是否其他假',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
